import { OrdersShippings } from './ordersShipping';
let _OrdersShippings = OrdersShippings;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import OrdersShippingMock from './mallm/orders/ordersShippingMock';
 * OrdersShippingMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mallm/orders/ordersShipping/listKey').reply(config => {
      let params = config.params;
      let mockOrdersShippings = _OrdersShippings.filter(ordersShipping => {
      	if(params.id||params.id==''){ if( ordersShipping.id.indexOf(params.id)>=0) return true;}
      	if(params.shippingStatus||params.shippingStatus==''){ if( ordersShipping.shippingStatus.indexOf(params.shippingStatus)>=0) return true;}
      	if(params.consignee||params.consignee==''){ if( ordersShipping.consignee.indexOf(params.consignee)>=0) return true;}
      	if(params.country||params.country==''){ if( ordersShipping.country.indexOf(params.country)>=0) return true;}
      	if(params.province||params.province==''){ if( ordersShipping.province.indexOf(params.province)>=0) return true;}
      	if(params.city||params.city==''){ if( ordersShipping.city.indexOf(params.city)>=0) return true;}
      	if(params.district||params.district==''){ if( ordersShipping.district.indexOf(params.district)>=0) return true;}
      	if(params.address||params.address==''){ if( ordersShipping.address.indexOf(params.address)>=0) return true;}
      	if(params.mobile||params.mobile==''){ if( ordersShipping.mobile.indexOf(params.mobile)>=0) return true;}
      	if(params.postscript||params.postscript==''){ if( ordersShipping.postscript.indexOf(params.postscript)>=0) return true;}
      	if(params.shippingId||params.shippingId==''){ if( ordersShipping.shippingId.indexOf(params.shippingId)>=0) return true;}
      	if(params.shippingName||params.shippingName==''){ if( ordersShipping.shippingName.indexOf(params.shippingName)>=0) return true;}
      	if(params.shippingFee||params.shippingFee==''){ if( ordersShipping.shippingFee.indexOf(params.shippingFee)>=0) return true;}
      	if(params.addTime||params.addTime==''){ if( ordersShipping.addTime.indexOf(params.addTime)>=0) return true;}
      	if(params.districtId||params.districtId==''){ if( ordersShipping.districtId.indexOf(params.districtId)>=0) return true;}
      	if(params.deptid||params.deptid==''){ if( ordersShipping.deptid.indexOf(params.deptid)>=0) return true;}
      	if(params.orderId||params.orderId==''){ if( ordersShipping.orderId.indexOf(params.orderId)>=0) return true;}
      	if(params.userid||params.userid==''){ if( ordersShipping.userid.indexOf(params.userid)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockOrdersShippings
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mallm/orders/ordersShipping/list').reply(config => {
      let params = config.params;
      let mockOrdersShippings = _OrdersShippings.filter(ordersShipping => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(ordersShipping.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shippingStatus||params.shippingStatus==''){if(ordersShipping.shippingStatus.indexOf(params.shippingStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.consignee||params.consignee==''){if(ordersShipping.consignee.indexOf(params.consignee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.country||params.country==''){if(ordersShipping.country.indexOf(params.country)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.province||params.province==''){if(ordersShipping.province.indexOf(params.province)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.city||params.city==''){if(ordersShipping.city.indexOf(params.city)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.district||params.district==''){if(ordersShipping.district.indexOf(params.district)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.address||params.address==''){if(ordersShipping.address.indexOf(params.address)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.mobile||params.mobile==''){if(ordersShipping.mobile.indexOf(params.mobile)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.postscript||params.postscript==''){if(ordersShipping.postscript.indexOf(params.postscript)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shippingId||params.shippingId==''){if(ordersShipping.shippingId.indexOf(params.shippingId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shippingName||params.shippingName==''){if(ordersShipping.shippingName.indexOf(params.shippingName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shippingFee||params.shippingFee==''){if(ordersShipping.shippingFee.indexOf(params.shippingFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.addTime||params.addTime==''){if(ordersShipping.addTime.indexOf(params.addTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.districtId||params.districtId==''){if(ordersShipping.districtId.indexOf(params.districtId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.deptid||params.deptid==''){if(ordersShipping.deptid.indexOf(params.deptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderId||params.orderId==''){if(ordersShipping.orderId.indexOf(params.orderId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userid||params.userid==''){if(ordersShipping.userid.indexOf(params.userid)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockOrdersShippings
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockOrdersShippings.length;
      mockOrdersShippings = mockOrdersShippings.filter((ordersShipping, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockOrdersShippings,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mallm/orders/ordersShipping/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _OrdersShippings = _OrdersShippings.filter(ordersShipping => ordersShipping.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mallm/orders/ordersShipping/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _OrdersShippings = _OrdersShippings.filter(ordersShipping => !params.includes(ordersShipping.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mallm/orders/ordersShipping/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,shippingStatus,consignee,country,province,city,district,address,mobile,postscript,shippingId,shippingName,shippingFee,addTime,districtId,deptid,orderId,userid } = params;
      _OrdersShippings.some(ordersShipping => {
        if (ordersShipping.id === id) {
			ordersShipping.id = id;
			ordersShipping.shippingStatus = shippingStatus;
			ordersShipping.consignee = consignee;
			ordersShipping.country = country;
			ordersShipping.province = province;
			ordersShipping.city = city;
			ordersShipping.district = district;
			ordersShipping.address = address;
			ordersShipping.mobile = mobile;
			ordersShipping.postscript = postscript;
			ordersShipping.shippingId = shippingId;
			ordersShipping.shippingName = shippingName;
			ordersShipping.shippingFee = shippingFee;
			ordersShipping.addTime = addTime;
			ordersShipping.districtId = districtId;
			ordersShipping.deptid = deptid;
			ordersShipping.orderId = orderId;
			ordersShipping.userid = userid
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mallm/orders/ordersShipping/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,shippingStatus,consignee,country,province,city,district,address,mobile,postscript,shippingId,shippingName,shippingFee,addTime,districtId,deptid,orderId,userid } = params;
      _OrdersShippings.push({
		id:id,
		shippingStatus:shippingStatus,
		consignee:consignee,
		country:country,
		province:province,
		city:city,
		district:district,
		address:address,
		mobile:mobile,
		postscript:postscript,
		shippingId:shippingId,
		shippingName:shippingName,
		shippingFee:shippingFee,
		addTime:addTime,
		districtId:districtId,
		deptid:deptid,
		orderId:orderId,
		userid:userid
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};